local skel = fk.CreateSkill{
  name = "lb__ningyue",
}

Fk:loadTranslationTable{
  ["lb__ningyue"] = "凝月",
  [":lb__ningyue"] = "一名角色于本轮首次因弃置失去黑色牌后，你可将之当冰【杀】使用。",

  ["#lb__ningyue"] = "凝月：你可以使用冰【杀】",

  ["$lb__ningyue1"] = "我以月色为剑。",
  ["$lb__ningyue2"] = "身外浮名，如云散尽。",
  ["$lb__ningyue3"] = "你无处可逃。",
}

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      local ids = {}
      local room = player.room
      local event_id = room.logic:getCurrentEvent().id

      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          if move.moveReason == fk.ReasonDiscard and move.from and move.proposer then
            
            if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
              for _, m in ipairs(e.data) do --完全一致的筛选
                if m.toArea == Card.DiscardPile then
                  if m.moveReason == fk.ReasonDiscard and m.from and m.proposer
                  and m.from == move.from then
                    for _, info in ipairs(m.moveInfo) do
                      if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                      Fk:getCardById(info.cardId).color == Card.Black and 
                      e.id ~= event_id then --在这对比
                        return true
                      end
                    end
                  end
                end
              end
            end, Player.HistoryRound) > 0 then return end
            
            
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
              Fk:getCardById(info.cardId).color == Card.Black and
              room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      ids = player.room.logic:moveCardsHoldingAreaCheck(ids)
      if #ids > 0 then
        event:setCostData(self, {cards = ids})
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(event:getCostData(self).cards)
    if #ids > 0 then
      local use = room:askToUseVirtualCard(player,{
        name = "ice__slash",
        subcards = ids,
        skill_name = skel.name,
        prompt = "#lb__ningyue",
        skip = true,
      })
      event:setCostData(self,{use = use})
      return use
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:useCard(event:getCostData(self).use)
  end,
})

return skel